package eg.com.itiga.ui.actions;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import eg.com.itiga.business.factory.BusinessFactory;
import eg.com.itiga.business.itian.ItianService;
import eg.com.itiga.domain.Itian;
import eg.com.itiga.ui.beans.SearchItianPageForm;

public class SearchItianAction extends org.apache.struts.action.Action {
    


    
    public SearchItianAction() {
    }
    
    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
        // TODO: Write method body
        //throw new UnsupportedOperationException("Method is not implemented");
    	System.out.println("Ana hena fel action");
    	
    	ActionForward forward = new ActionForward () ;
    	String name = ((SearchItianPageForm)form).getItianName();
    	int department = ((SearchItianPageForm)form).getDepartment();
    	int intake = ((SearchItianPageForm)form).getIntake();
       	System.out.println("Itian Name is : " + ((SearchItianPageForm)form).getItianName());
    	System.out.println("Itian Name is : " + ((SearchItianPageForm)form).getDepartment());
    	System.out.println("Itian Name is : " + ((SearchItianPageForm)form).getIntake());
    	BusinessFactory factory = new BusinessFactory ();
    	ItianService itianService = factory.createItianService(); 
    	List<Itian> itians = itianService.SearchItian(name, department, intake);
    	ItianSearchResult searchResult = new ItianSearchResult ();
    	searchResult.setItians(itians);
    	if (itians != null)
    		System.out.println("Done and the result is " + itians.size());
    	else 
    		System.out.println("NULL Leeh yad :(");
    	forward = mapping.findForward("searchItianResult");
    	return forward;
    }

}